package com.greenzebras.geocache;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

import com.greenzebras.geocache.datastore.persistence.GeocacheDataService;

//this is to prevent warnings. Spoke with andy and he says it is OK to use this
@SuppressWarnings("deprecation")
public class GeocacheMainTabbedActivity extends TabActivity {
	private static final int START_TAB_INDEX = 0;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		// initialize the data service
		GeocacheDataService.INSTANCE
				.initGeocacheDataService(getApplicationContext());
		
		setContentView(R.layout.main);
		createTabSpecs();
		getTabHost().setCurrentTab(START_TAB_INDEX);

	}

	private void createTabSpecs() {
		TabHost tabHost = getTabHost();
		Resources resources = getResources();

		// Map view tab spec
		tabHost.addTab(createMapViewTab(tabHost, resources));
		// Search tab spec
		tabHost.addTab(createSearchTab(tabHost, resources));
		// Create Cache tab spec
		tabHost.addTab(createCreateCacheTab(tabHost, resources));
	}

	private TabHost.TabSpec createMapViewTab(final TabHost tabHost,
			final Resources resources) {
		return tabHost
				.newTabSpec("map_view")
				.setIndicator("Map View",
						resources.getDrawable(R.drawable.ic_tab_map))
				.setContent(
						new Intent().setClass(this,
								GeocacheMapViewActivity.class));
	}

	private TabHost.TabSpec createSearchTab(final TabHost tabHost,
			final Resources resources) {
		return tabHost
				.newTabSpec("search")
				.setIndicator("Search",
						resources.getDrawable(R.drawable.ic_tab_search))
				.setContent(
						new Intent().setClass(this,
								GeocacheSearchFormActivity.class));
	}

	private TabHost.TabSpec createCreateCacheTab(final TabHost tabHost,
			final Resources resources) {
		return tabHost
				.newTabSpec("create_cache")
				.setIndicator("Create Cache",
						resources.getDrawable(R.drawable.ic_tab_add))
				.setContent(
						new Intent().setClass(this,
								GeocacheLocationSearchActivity.class));
	}
}